﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CSharpCodeAssistant
{
    public partial class RenamePropertyForm : Form
    {
        string propertyName = null;
        CodeGenerator codeGenerator;
        /// <summary>
        /// default constructor.
        /// </summary>
        public RenamePropertyForm()
        {
            InitializeComponent();
            CenterToScreen();
        }

        /// <summary>
        /// internal constructor.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="variableName"></param>
        /// <param name="codeGenerator"></param>
        internal RenamePropertyForm(String propertyName, String variableName,CodeGenerator codeGenerator)
            : this()
        {
            this.propertyName = propertyName;
            variableValueLabel.Text = variableName;
            propertyNameTextBox.Text = propertyName;
            propertyNameTextBox.SelectAll();
            this.codeGenerator = codeGenerator;
        }

        /// <summary>
        /// read only property for propertyName variable
        /// </summary>
        internal string PropertyName
        {
            get
            {
                return propertyName;
            }           
        }

        private void finishButton_Click(object sender, EventArgs e)
        {
            propertyName = propertyNameTextBox.Text;
            if (codeGenerator.CheckIfPropertyExists(PropertyName))
            {
                propertyNameTextBox.Text = propertyName;
                propertyNameTextBox.SelectAll();
                propertyName=null;
            }
            else
            {
                this.Hide();
                this.Close();
                this.Dispose();
            }
        }

        private void ignoreButton_Click(object sender, EventArgs e)
        {
            propertyName = null;
            this.Hide();
            this.Close();
            this.Dispose();
        }


    }
}
